package ru.papergames.battleserver.model.battle.npc.processors;

import ru.papergames.battleserver.model.battle.AbstractBattle;
import ru.papergames.battleserver.model.battle.BattlePlayer;
import ru.papergames.battleserver.model.battle.npc.NpcCell;

import java.util.Random;

/**
 * TODO: add description
 * Date: 11.05.12 21:55
 *
 * @author Alexander Troshanin
 */
public abstract class AbstractNpcActionProcessor implements NpcActionProcessor {

    protected Random rnd = new Random();

    public void processNpcAction(AbstractBattle battle, BattlePlayer npcPlayer) {

        if (npcPlayer == null) {
            return;
        }
        if (!battle.isPlayerMovingNow(npcPlayer) || npcPlayer.isLastActionStillProceeds()) {
            return;
        }
        processPlayer(battle, npcPlayer);
    }

    protected abstract void processPlayer(AbstractBattle battle, BattlePlayer npcPlayer);

    protected int distance(NpcCell c1, NpcCell c2) {
        return Math.abs(c1.getX() - c2.getX()) + Math.abs(c1.getY() - c2.getY());
    }
}

